import { get_agreement } from '@/services/privacy';
import { useEffect, useState } from 'react';

const TermOfService = () => {
  // 存储服务协议内容
  const [content, setContent] = useState<any>();
  // 获取URL参数
  const getUrlParam = (name: string) => {
    const reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`);
    const r = window.location.search.substr(1).match(reg);
    if (r != null) {
      return decodeURIComponent(r[2]);
    }
    return null;
  };
  // 获取协议类型
  const type: any = getUrlParam('type');
  // 获取那个端
  const project_id: any = getUrlParam('project_id');
  // 获取隐私协议
  useEffect(() => {
    const getData = async () => {
      let request_body = {
        project_id,
        type,
      };
      let res: any = await get_agreement(request_body);
      console.log('res', res);
      if (res.code == 200) {
        setContent(res.data?.content);
      }
    };
    getData();
  }, []);
  return <div style={{ padding: '30px 20px' }} dangerouslySetInnerHTML={{ __html: content }}></div>;
};
export default TermOfService;
